package com.icbc.digitalwallet.controller;


import com.icbc.digitalwallet.common.util.JwtUtils;
import com.icbc.digitalwallet.common.util.R;
import com.icbc.digitalwallet.pojo.VO.CardInfoAndTransInfo;
import com.icbc.digitalwallet.pojo.VO.TransVO;
import com.icbc.digitalwallet.pojo.entity.Card;
import com.icbc.digitalwallet.service.CardService;
import com.icbc.digitalwallet.service.DigitalWalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tx
 * @since 2021-07-17
 */
@RestController
@RequestMapping("/card")
@Api(tags = "卡式钱包")
@Slf4j
public class CardController {
    @Autowired
    private CardService cardService;

    @PostMapping("/getCardInfo")
    @ApiOperation("获取卡式软钱包的信息和交易信息")
    public R getCardInfoAndTrans(@RequestParam("cardId") String id,
                                 @RequestParam(value = "type",required = false) Integer type){
        //根据id获取卡式软钱包的信息和交易信息
        CardInfoAndTransInfo card = cardService.getCardInfoAndTrans(id, type);
        return R.ok().data("cardInfo", card);

    }

    @PostMapping("/establishCard")
    @ApiOperation("卡式软钱包开立")
    public R CardEstablish(@RequestParam("cardId") String id){
        cardService.CardEstablish(id);
        return R.ok().message("开卡成功!");
    }



    @PostMapping("/reCharge")
    @ApiOperation("卡式钱包充值 数字钱包-->卡式钱包")
    public R cho(@RequestParam("id") String id,
                      @RequestBody TransVO transVO){

        cardService.cho(id,transVO);
        return R.ok().message("卡式钱包充值成功");
    }


    @PostMapping("/withDraw")
    @ApiOperation("/卡式钱包提现 卡式钱包-->数字钱包")
    public R tix(@RequestParam("cid") String cid,
                 @RequestParam("wid") String wid){

        cardService.tix(cid,wid);
        return R.ok().message("卡式提现成功");

    }
}

